package cn.edu.lingnan.servlet;

import cn.edu.lingnan.pojo.User;
import cn.edu.lingnan.service.userservice;
import cn.edu.lingnan.service.userserviceimp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/StudentUpdate")
public class StudentUpdateServlet extends HttpServlet {
    userservice us=new userserviceimp();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        Integer id =Integer.parseInt(req.getParameter("id")) ;
        String name = req.getParameter("name");
        String ageStr = req.getParameter("age");
        String gender = req.getParameter("gender");
        System.out.println("性别"+gender);
        String major = req.getParameter("major");
        System.out.println("专业"+major);
        String clname = req.getParameter("clname");
        String address = req.getParameter("address");
        String phone = req.getParameter("phone");
        int age = Integer.parseInt(ageStr);
        User user = new User();
        user.setId(id);
        user.setName(name);
        user.setAge(age);
        user.setGender(gender);
        user.setMajor(major);
        user.setClname(clname);
        user.setAddress(address);
        user.setPhone(phone);
        System.out.println(" 更新学生信息 "+user);

        Integer success = us.StudentUpdate(user);
        if (success==1) {
            req.getSession().setAttribute("user", user);
            resp.getWriter().print("<script>alert('修改成功');window.location.href='student_my.jsp';</script>");
        } else {
            resp.getWriter().print("<script>alert('修改失败');window.location.href='student_my.jsp';</script>");
        }
    }

}
